<template>
<div class="app-container calendar-list-container">
  <div class="filter-container">
    <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="店铺名称" v-model="listQuery.shopName"> </el-input>
    <el-button class="filter-item" type="primary" v-waves icon="search" @click="handleFilter">搜索</el-button>
    <el-button class="filter-item"  style="margin-left: 10px;" @click="addShops" type="primary" icon="edit">添加</el-button>
  </div>
  <el-table :key='tableKey' :data="list" v-loading.body="listLoading" border fit highlight-current-row style="width: 100%">
    <el-table-column align="center" label="编号" min-width="10%"> 
      <template scope="scope">
          <span>{{scope.row.shopId}}</span>
      </template> 
    </el-table-column>
    <el-table-column min-width="10%" align="center" label="店铺名称"> 
      <template scope="scope">
        <span>{{scope.row.shopName}}</span>
      </template> 
    </el-table-column>
    <el-table-column min-width="10%" align="center" label="店铺门头"> 
      <template scope="scope">
        <el-popover placement="right" title="" trigger="hover">
          <img slot="reference" :src="imgBaseURL + scope.row.banner" min-width="70" height="70">
          <img :src="imgBaseURL + scope.row.banner" style="max-height: 300px;max-width: 300px">
        </el-popover>
      </template> 
    </el-table-column>
    <el-table-column min-width="10%" align="center" label="联系人"> 
      <template scope="scope">
        <span>{{scope.row.linkMan}}</span>
        </template> 
    </el-table-column>
    <el-table-column min-width="10%" align="center" label="手机号码"> 
      <template scope="scope">
          <span>{{scope.row.mobile}}</span>
        </template> 
    </el-table-column>
    <el-table-column min-width="20%" align="center" label="地址"> 
      <template scope="scope">
        <span>{{scope.row.address}}</span>
      </template> 
    </el-table-column>
    <el-table-column min-width="10%" align="center" label="二维码"> 
      <template scope="scope">
        <el-popover placement="right" title="" trigger="hover">
          <img slot="reference" :src="imgBaseURL + scope.row.qrcode" min-width="70" height="70">
          <img :src="imgBaseURL + scope.row.qrcode" style="max-height: 200px;max-width: 200px">
        </el-popover>
      </template> 
    </el-table-column>
    <el-table-column min-width="10%" align="center" label="浏览人数"> 
      <template scope="scope">
        <span>{{scope.row.viewCount}}</span>
      </template> 
    </el-table-column>
    <el-table-column min-width="10%" align="center" label="点赞人数"> 
      <template scope="scope">
        <span>{{scope.row.fansCount}}</span>
      </template> 
    </el-table-column>
     <el-table-column align="center" label="操作" min-width="20%"> <template scope="scope">
        <el-button  size="small" type="success" @click="handleUpdate(scope.row)">编辑</el-button>
        <el-button  size="small" type="danger" @click="homeManagement(scope.row)">首页管理</el-button>
      </template> </el-table-column>
  </el-table>
  <div v-show="!listLoading" class="pagination-container">
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="listQuery.pageNo" :page-sizes="[10,20,30, 50]" :page-size="listQuery.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination>
  </div>
</div>
</template>

<script>
import {
  page
} from 'api/shop/shops/index';
import { mapGetters } from 'vuex';
export default {
  name: 'shopManage',
  data() {
    return {
      imgBaseURL: this.GLOBAL.imgBaseURL,
      list: null,
      total: null,
      listLoading: true,
      listQuery: {
        pageNo: 1,
        pageSize: 20,
        shopName: undefined
      },
      tableKey: 0
    }
  },
  created() {
    this.getList();
  },
  computed: {
    ...mapGetters([
      'elements'
    ])
  },
  methods: {
    getList() {
      this.listLoading = true;
      page(this.listQuery)
        .then(response => {
          this.list = response.data.rows;
          this.total = response.data.total;
          this.listLoading = false;
        })
    },
    handleFilter() {
      if(this.dateRange != null){
        this.listQuery.startTime = this.dateRange[0];
        this.listQuery.endTime = this.dateRange[1];
      }
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNo = val;
      this.getList();
    },
    addShops(){
      this.$router.push('/shop/shops/addShops')
    },
    handleUpdate(row){
      this.$router.push({path:'/shop/shops/updateShops',query:{id:row.shopId}});
    },
    homeManagement(row){
      this.$router.push({path:'/shop/shops/managementShops',query:{id:row.shopId,name:row.shopName}});
    }
  }
}
</script>